package com.naiterui.ehp.bs.patient.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.naiterui.ehp.bp.domain.charge.DrServiceItems;
import com.naiterui.ehp.bs.patient.dao.IDrServiceItemDao;
import com.naiterui.ehp.bs.patient.repository.IApDrServiceItemRepository;

@Component
public class ApDrServiceItemDaoImpl implements IDrServiceItemDao {

    @Autowired
    private IApDrServiceItemRepository drServiceItemRepository;

    @Override
    public DrServiceItems getDoctorChargeItems(Long doctorId) {
        return drServiceItemRepository.findFirstByDoctorId(doctorId);
    }

    @Override
    public Map<Long, DrServiceItems> getDoctorChargeItemsMap(List<Long> doctorIdList) {
        if (doctorIdList == null) {
            return null;
        }
        String idStr = doctorIdList.toString();
        if (idStr != null && idStr.length() >= 3) {
            Map<Long, DrServiceItems> doctorChargeItemsMap = new HashMap<>();

            List<DrServiceItems> serviceItemsList = drServiceItemRepository.findByDoctorIdIn(doctorIdList);

            if (serviceItemsList != null && serviceItemsList.size() > 0) {
                for (DrServiceItems dsi : serviceItemsList) {
                    doctorChargeItemsMap.put(dsi.getDoctorId(), dsi);
                }
            }

            return doctorChargeItemsMap;
        } else {
            return null;
        }
    }

}
